package com.util.email;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

public class Emailsender {
    public Emailsender(){
        
    }
    public boolean sendMail(ErrorMailInterface errorMail){
        HtmlEmail email = new HtmlEmail();
        try {
            initMail(email, errorMail);
            email.send();
        } catch (EmailException e) {
            return false;
        }
        return true;
    }
    private void initMail(HtmlEmail email, ErrorMailInterface errorMail) throws EmailException {
        email.setHostName(errorMail.getMail_smtp_host());
        email.setFrom(errorMail.getFromAddress(), errorMail.getFromAddress());
        email.setAuthentication(errorMail.getUsername(), errorMail.getPassword());
        for(String oneaddressee:errorMail.getAddressee()){
            email.addTo(oneaddressee);
        }
        email.setCharset("UTF-8");
        email.setSubject(errorMail.getTitle());
        email.setHtmlMsg(errorMail.getMessage());
        //.setMsg(errorMail.getMessage());
    }
}
